package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书...");
        System.out.println("请输入您要新增图书的书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int currtenSize = bookList.getUsedSize();
        for (int i = 0; i < currtenSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                System.out.println("已有该书...");
                System.out.println(book);
                return ;
            }
        }
//        插入到最后位置
        System.out.println("请输入您要新增图书的作者：");
        String author = scanner.nextLine();
        System.out.println("请输入您要新增图书的价格：");
        int price = scanner.nextInt();
        scanner.nextInt();
        System.out.println("请输入您要新增图书的类型：");
        String type = scanner.nextLine();

        Book book = new Book(name,author,price,type);
        bookList.setBooks(currtenSize,book);
        bookList.setUsedSize(currtenSize + 1);
        System.out.println("添加成功... ");
    }
}
